﻿
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- saved from url=(0014)about:internet -->
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:mssdk="winsdk" xmlns:script="urn:script" xmlns:build="urn:build" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="Description" content="You can use Microsoft Visual Studio to set up and perform kernel-mode debugging of a virtual machine."/>
<meta name="MSHAttr" content="PreferredSiteName:MSDN"/>
<meta name="MSHAttr" content="PreferredLib:/library/windows/hardware"/>
<title>Setting Up Kernel-Mode Debugging of a Virtual Machine in Visual Studio</title>



<link rel="STYLESHEET" type="text/css" HREF="../common/backsdk4.css"/>





<style>
html,div { margin: 0; padding: 0;}

body {
	padding: 0px;
	margin: 0px;
	overflow: auto;
	height: 100%;
}

#winchm_template_button{
	float: right;
	width: 93px;
	top: 7px;
	position: relative;
	text-align: right;
	right: 5px;
	height: auto;
}

#winchm_template_top{
	padding: 0px;
	margin: 0px;
	border-bottom: 1px solid #9B9B9B;
	background-color: #B1CEFE;
}

#winchm_template_navigation{
	margin: 0px;
	padding-top: 7px;
	padding-left: 7px;
	padding-bottom: 3px;
	padding-right: 0px;
	font-size: 8.5pt;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: normal;
	color: #585858;
}

#winchm_template_title{
	margin: 0px;
	padding-top: 4px;
	padding-left: 7px;
	padding-bottom: 7px;
	padding-right: 0px;
	font-size: 18px; 
	font-family: Verdana, Geneva, sans-serif;
	color: #363636;
}

#winchm_template_content{
	margin-top: 20px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	width: auto  !important;
	width: 100%;
}

#winchm_template_footer{
	border-width: 1px;
	border-color: #B1CEFE;
	border-top-style: solid;
	margin-top: 15px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	padding-top: 7px;
	padding-left: 0px;
	padding-bottom: 0px;
	padding-right: 0px;
	font-family: arial, helvetica, sans-serif;
	font-size: 8.5pt;
	color: #696969;
	width: auto;
	text-align: left;
}


#winchm_template_container{
	margin: 0px;
	padding: 0px;
	position: static;
	padding-bottom: 3px;
	overflow: auto;
	background-color: #FFFFFF;
}


@media print
{
#winchm_template_container{
	position: static;	
	margin: 0px;
	padding: 5px;
	
	width: auto;
	height: auto;
	overflow: auto;
}
#winchm_template_button{
visibility:hidden;
}
}

#winchm_template_navigation A:link	{text-decoration: none; color:#004080}
#winchm_template_navigation A:visited  {text-decoration: none; color: #004080}
#winchm_template_navigation A:active {text-decoration: none; color: #004080 }
#winchm_template_navigation A:hover {text-decoration: none;color: #0080FF}

A:link	{text-decoration: underline; color:#0033CC}
A:visited  {text-decoration: underline; color: #0033CC}
A:active {text-decoration: underline; color: #0033CC }
A:hover {text-decoration: underline;color: #FF0000;}
</style>
<script type="text/javascript">
function isMobile(){
Agent = window.navigator.userAgent;
if (Agent.indexOf("iPhone")>=1 || Agent.indexOf("iPad")>=1 || Agent.indexOf("iPod")>=1 || Agent.indexOf("Android")>=1){
return true;
}else{
return false;	
}

}
function d_onresize(){
if (window.navigator.userAgent.indexOf("MSIE")>=1){
document.getElementById('winchm_template_container').style.pixelWidth = document.body.offsetWidth - 3;
document.getElementById('winchm_template_container').style.pixelHeight = document.body.offsetHeight - document.getElementById('winchm_template_top').offsetHeight - 4;
}
document.getElementById('winchm_template_container').style.top = document.getElementById('winchm_template_top').offsetHeight + 'px';
}

function d_onbeforeprint(){
document.getElementById('winchm_template_container').style.width = 'auto';
document.getElementById('winchm_template_container').style.height = 'auto';
}

function d_onafterprint(){
d_onresize();
}

if(!isMobile()){

window.onload = d_onresize;
window.onresize = d_onresize;
window.onbeforeprint = d_onbeforeprint;
window.onafterprint = d_onafterprint;

document.write("<style>\n");
document.write("body {overflow: hidden;}\n");
document.write("#winchm_template_container {position: absolute;overflow: auto;top : 0px;right: 0px;bottom: 0px;left: 0px;}\n");
document.write("</style>\n");
}

</script>
</head>
<body><script language="JavaScript" type="text/JavaScript">
function syn(){
if(parent.nav.tree){
 if(parent.nav.tree.loaded){
  parent.nav.tree.selectNode(14);
 }else{
  setTimeout("syn()",500);
}
  }else{
  setTimeout("syn()",500);
  }}
if(parent!=self){
  setTimeout("syn()",100);
}else{
  parent.location.href = "../../index.htm?page=debugger/setting_up_a_connection_to_a_virtual_machine_in_visual_studio.htm";
}
originalOnload = window.onload;
if(originalOnload==null){
window.onload = function(){parent.contentLoaded = true;};
}else{
window.onload = function(){originalOnload();parent.contentLoaded = true;};
}
</script> 


<div id="winchm_template_top">
	<div id="winchm_template_button"><A href="setting_up_kernel-mode_debugging_using_serial_over_usb_in_visual_studio.htm" title="Previous topic"><img id="winchm_template_prev" alt="Previous topic" src="../template2/btn_prev_n.gif" border="0"></a><A href="setting_up_kernel-mode_debugging_in_windbg__cdb__or_ntsd.htm" title="Next topic"><img id="winchm_template_next" alt="Next topic" src="../template2/btn_next_n.gif" border="0"></a></div>
	<div id="winchm_template_navigation">Help &gt; 
<A href="introduction6.htm">Debugging Tools for Windows (WinDbg, KD, CDB, NTSD)</A> &gt; <A href="getting_started_with_windows_debugging.htm">Getting Started with Windows Debugging</A> &gt; <A href="getting_set_up_for_debugging.htm">Setting Up Debugging (Kernel-Mode and User-Mode)</A> &gt; <A href="setting_up_kernel-mode_debugging_in_visual_studio.htm">Setting Up Kernel-Mode Debugging in Visual Studio</A> &gt; </div>
	<div id="winchm_template_title">Setting Up Kernel-Mode Debugging of a Virtual Machine in Visual Studio</div>
</div>
<div id="winchm_template_container">
	<div id="winchm_template_content"><div id="mainSection"><p>You can use Microsoft Visual Studio to set up and perform kernel-mode debugging of a virtual machine. The virtual machine can be located on the same physical computer as the debugger or on a different computer that is connected to the same network. To use Visual Studio for kernel-mode debugging, you must have the Windows Driver Kit (WDK) integrated with Visual Studio. For information about how to install the integrated environment, see <a href="http://go.microsoft.com/fwlink/p?linkid=301383">Windows Driver Development</a>.</p>
<p>As an alternative to using Visual Studio to set up debugging of a virtual machine, you can do the setup manually. For more information, see <a href="#Bookmark22">Setting Up Kernel-Mode Debugging of a Virtual Machine Manually</a>.</p>
<p>The computer that runs the debugger is called the <i>host computer</i>, and the virtual machine that is being debugged is called the <i>target virtual machine</i>.</p>
<h2><a id="Configuring_the_Target_Virtual_Machine"></a><a id="configuring_the_target_virtual_machine"></a><a id="CONFIGURING_THE_TARGET_VIRTUAL_MACHINE"></a>Configuring the Target Virtual Machine</h2>
<ol>
<li>
<p>In the virtual machine, in an elevated Command Prompt window, enter the following commands.</p>
<dl>
<dd><b>bcdedit /debug on</b></dd>
<dd><b>bcdedit /dbgsettings serial debugport:</b><i>n</i><b> baudrate:115200 
</b><p>where <i>n</i> is the number of a COM port on the virtual machine.</p>
</dd>
</dl>
<div class="alert"><b>Note</b>  By default, COM ports are not presented in generation 2 virtual machines. For information about how to create a COM port, see <a href="#Bookmark14">Generation 2 Virtual Machines</a>.</div>
<div> </div>
</li>
<li>Reboot the virtual machine.</li>
<li>In the virtual machine, configure the COM port to map to a named pipe. 

The debugger will connect through this pipe. For more information about how to create this pipe, see your virtual machine's documentation.</li>
</ol>
<h2><a id="Configuring_the_Host_Computer"></a><a id="configuring_the_host_computer"></a><a id="CONFIGURING_THE_HOST_COMPUTER"></a>Configuring the Host Computer</h2>
<p>The host computer can be the same physical computer that is running the virtual machine, or it can be a separate computer.</p>
<ol>
<li>On the host computer, in Visual Studio, on the <b>Driver</b> menu, choose <b>Test &gt; Configure Computer</b>.</li>
<li>Click <b>Add New Computer</b>.</li>
<li>For <b>Computer name</b>, enter the name of the physical computer that is running the target virtual machine.</li>
<li>Select <b>Manually configure debuggers and do not provision</b>, and click <b>Next</b>.</li>
<li>For <b>Connection Type</b>, select <b>Serial</b>.</li>
<li>Check <b>Pipe</b>, and check <b>Reconnect</b>.</li>
<li>
<p>If the debugger is running on the same computer as the virtual machine, enter the following for <b>Pipe name</b>:</p>
<p><b>\\.\pipe\</b><i>PipeName</i>. </p>
<p>If the debugger is running on a different computer from the virtual machine, enter the following for <b>Pipe name</b>:</p>
<p><b>\\</b><i>VMHost</i><b>\pipe\</b><i>PipeName</i></p>
<p>where, <i>VMHost</i> is the name of the physical computer that is running the target virtual machine, and <i>PipeName</i> is the name of the pipe that you associated with the COM port on the target virtual machine. </p>
</li>
<li>Click <b>Next</b>. Click <b>Finish</b>.</li>
</ol>
<h2><a id="Starting_the_Debugging_Session"></a><a id="starting_the_debugging_session"></a><a id="STARTING_THE_DEBUGGING_SESSION"></a>Starting the Debugging Session</h2>
<ol>
<li>On the host computer, in Visual Studio, on the <b>Tools</b> menu, choose <b>Attach to Process</b>.</li>
<li>For <b>Transport</b>, choose <b>Windows Kernel Mode Debugger</b>.</li>
<li>For <b>Qualifier</b>, select the name of the physical computer that is running the target virtual machine.</li>
<li>Click <b>Attach</b>.</li>
</ol>
<h2><a id="generation_2_virtual_machines"></a><a id="GENERATION_2_VIRTUAL_MACHINES"></a>Generation 2 Virtual Machines</h2>
<p>By default, COM ports are not presented in generation 2 virtual machines. You can add COM ports through PowerShell or WMI. For the COM ports to be displayed in the Hyper-V Manager console, they must be created with a path.</p>
<p>To enable kernel debugging using a COM port on a generation 2 virtual machine, follow these steps:
</p>
<ol>
<li>
<p>Disable Secure Boot by entering this PowerShell command:</p><b>Set-VMFirmware –Vmname </b><i>VmName</i><b> –EnableSecureBoot Off
</b><p>where <i>VmName</i> is the name of your virtual machine.</p>
</li>
<li>
<p>Add a COM port to the virtual machine by entering this PowerShell command:</p><b>Set-VMComPort –VMName </b><i>VmName</i><b> 1 \\.\pipe\</b><i>PipeName</i><p>For example, the following command configures the first COM port on virtual machine TestVM to connect to named pipe TestPipe on the local computer.</p><b>Set-VMComPort –VMName TestVM 1 \\.\pipe\TestPipe
</b></li>
</ol>
<p>For more information, see <a href="http://go.microsoft.com/fwlink/p/?Linkid=331326">Generation 2 Virtual Machine Overview</a>.</p>
<h2><a id="related_topics"></a>Related topics</h2>
<dl>
<dt><a href="#Bookmark7">Setting Up Kernel-Mode Debugging in Visual Studio</a></dt></dl></div></div>	
	<div id="winchm_template_footer">Copyright &copy; 2019. All rights 
reserved. (To change the copyright info, just edit it in template.)</div>
</div>

</body>
</html>
